// import rpc from '@/odoorpc'
// const baseURL = process.env.VUE_APP_BASE_API
// const timeout = 50000
// rpc.init({ baseURL, timeout })

// import Test from './testcase'

// const master_pwd = '123'
// const login_info = { db: 'test_db', login: 'admin', password: '123456' }
// // const config = { master_pwd }
// const config = { master_pwd, login_info }
// const test = new Test(config)

import api from '@/odoorpc'

const test = {
  login: async () => {
    const db = process.env.VUE_APP_ODOO_DB
    const username = 'user1@comp1'
    const password = '123456'
    const res = await api.web.session.authenticate({
      db,
      login: username,
      password
    })

    console.log('login', res)
    return res
  },

  session_info: () => {
    console.log('session_info')
    // const res = api.web.session
    const res = api.env

    console.log([res])

    // return res
  },

  user_info: async () => {
    const uid = api.env.uid
    const Model = api.env.model('res.users')
    const res = await Model.read(uid, ['name', 'email', 'company_id'])
    console.log('user_info', res)
    // return res
  },

  user_model_fields: async () => {
    const Model = api.env.model('res.users')
    const allfields = []
    const attributes = []
    const res = await Model.fields_get(allfields, attributes)
    console.log('user_model_fields', res)
    // return res
  }
}

export const test_rpc = async () => {
  // alert('test rpc')
  await test.login()
  test.user_info()
  // await test.base_import.test()
  // await test_database_create()
  // await test_database_drop()
  // await test.base.version_info()
  // await test.database.test()
  // await test.session.test()
  // await test.dataset.test()
  // await test.model.test()
  // await test.context.test()
  // await test.ir_module.test()
  // await test.home.test()()
  //
  // TODO
  // await test.xml.test()
  // await test.export.test()
  // await test_export()
}

// async function test_database_create() {
//   // const master_pwd = this.master_pwd
//   const master_pwd = '123'
//   const name = 'db_for_test_create_drop'
//   const lang = 'zh_CN'
//   const password = '123456'
//   const kwargs = {
//     demo: false,
//     login: 'admin',
//     country_code: 'CN',
//     phone: ''
//   }

//   const database_list = await rpc.web.database.list()

//   if (database_list.includes(name)) {
//     console.log('database: ', name, 'is exist')
//     return
//   }

//   console.log('test database create:', name)
//   console.log('begin:', new Date().getTime(), new Date())
//   const payload = [master_pwd, name, lang, password, kwargs]
//   const res = await rpc.web.database.create(...payload)
//   console.log('end:', new Date().getTime(), new Date())
//   console.log('test database create:', res)
//   return res
// }

// async function test_database_drop() {
//   const master_pwd = '123'
//   const name = 'db_for_test_create_drop'

//   const database_list = await rpc.web.database.list()

//   if (!database_list.includes(name)) {
//     console.log('database: ', name, 'is not exist')
//     return
//   }

//   console.log('test database drop:', name)
//   console.log('begin:', new Date().getTime(), new Date())
//   const res = await rpc.web.database.drop(master_pwd, name)
//   console.log('end:', new Date().getTime(), new Date())
//   console.log('test database drop:', res)
//   return res
// }
